const { defineConfig } = require('@vue/cli-service')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
module.exports = defineConfig({
	//设置为空打包后不分更目录还是多级目录
	// publicPath:'/',
	// //build编译后存放静态文件的目录
	// assetsDir: "static",
	publicPath: '/',
	assetsDir: "static",
	// build编译后不生成资源MAP文件
	productionSourceMap: false,
	lintOnSave: false,
	
	//开发服务,build后的生产模式还需nginx代理
	devServer: {
		open: false, //运行后自动打开浏览器
		port: process.env.VUE_APP_PORT, //挂载端口
		hot: true, // 开启热加载  mm
		proxy: {
			'/api': {
				target: process.env.VUE_APP_API_BASEURL,
				ws: true,
				pathRewrite: {
					'^/api': '/'
				}
				
			}
		},
		// client: {
		// 	overlay: {
		// 	  errors: false,
		// 	  warnings: false,
		// 	},
		//   }
	},

	chainWebpack: config => {
		// 移除 prefetch 插件
		config.plugins.delete('preload');
		config.plugins.delete('prefetch');
		config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js');
	},

	configureWebpack:config=> {
		//性能提示
		config.performance={
			hints: false
		}
		config.optimization={
			splitChunks: {
				chunks: "all",
				automaticNameDelimiter: '~',
				name: "tsuiChunks",
				cacheGroups: {
					//第三方库抽离
					vendor: {
						name: "modules",
						test: /[\\/]node_modules[\\/]/,
						priority: -10
					},
					elicons: {
						name: "elicons",
						test: /[\\/]node_modules[\\/]@element-plus[\\/]icons-vue[\\/]/
					},
					tinymce: {
						name: "tinymce",
						test: /[\\/]node_modules[\\/]tinymce[\\/]/
					},
					echarts: {
						name: "echarts",
						test: /[\\/]node_modules[\\/]echarts[\\/]/
					},
					codemirror: {
						name: "codemirror",
						test: /[\\/]node_modules[\\/]codemirror[\\/]/
					},
					luckyexcel:{
						name: "luckyexcel",
						test: /[\\/]node_modules[\\/]luckyexcel[\\/]/
					}
				}
			}
		}
		const plugins = [];
        // 同externals一样，我们只想在生产环境下生成gzip即可
        if (process.env.NODE_ENV === 'production') {
            plugins.push(
                new CompressionWebpackPlugin({
                    filename: '[path][base].gz', // 生成的文件名
                    algorithm: 'gzip', // 类型
                    test: new RegExp('\\.(js|css)$'), // 匹配规则
                    threshold: 10240, // 字节数 只处理比这个大的资源
                    minRatio: 0.8 // 压缩率 只有比这个小的才会处理
                })
            )
        }
        config.plugins = [
            ...config.plugins,
            ...plugins
        ]
	}
})

